#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct Student{
	string name;
	int score[4];
};
Student stu[105];
bool cmp1(Student a,Student b){
	if(a.score[0]!=b.score[0]){
		return a.score[0]>b.score[0];
	}else{
		return a.name<b.name;
	}
}
bool cmp2(Student a,Student b){
	if(a.score[1]!=b.score[1]){
		return a.score[1]>b.score[1];
	}else{
		return a.name<b.name;
	}
}
bool cmp3(Student a,Student b){
	if(a.score[2]!=b.score[2]){
		return a.score[2]>b.score[2];
	}else{
		return a.name<b.name;
	}
}
bool cmp4(Student a,Student b){
	if(a.score[3]!=b.score[3]){
		return a.score[3]>b.score[3];
	}else{
		return a.name<b.name;
	}
}
bool cmp5(Student a,Student b){
	int suma = 0,sumb = 0;
	for(int i=0;i<4;i++){
		suma+=a.score[i];
		sumb+=b.score[i];
	}
	if(suma!=sumb){
		return suma>sumb;
	}else{
		return a.name<b.name;
	}
}
void print(int n){
	for(int i=0;i<n;i++){
		if(i!=n-1){
			cout << stu[i].name << " ";
		}else{
			cout << stu[i].name << endl;	
		}
	}
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> stu[i].name;
		for(int j=0;j<4;j++){
			scanf("%d",&stu[i].score[j]);
		}
	}
	sort(stu,stu+n,cmp1);
	print(n);
	sort(stu,stu+n,cmp2);
	print(n);
	sort(stu,stu+n,cmp3);
	print(n);
	sort(stu,stu+n,cmp4);
	print(n);
	sort(stu,stu+n,cmp5);
	print(n);
}
